//
//  AppDelegate+USocial.m
//  xk100
//
//  Created by xiaokang on 2017/5/2.
//  Copyright © 2017年 xiaokang. All rights reserved.
//


static NSString *const UMengAppKey      = @"58bfc4217f2c747688001063";

static NSString *const WeChatAppKey     = @"wx68a31271bb94b041";
static NSString *const WeChatAppSecret  = @"a617597c7ef48bec3a627448bab9e1b1";

static NSString *const QQAppKey         = @"1106025633";
static NSString *const QQAppSecret      = nil; // 不需要

static NSString *const SinaAppKey       = @"3962076010";
static NSString *const SinaAppSecret    = @"8467c6a694a05f407c15b40bf3b3ad7a";

static NSString *const AliPayAppKey       = @"2017042606973433";
static NSString *const AliPayAppSecret    = @"8467c6a694a05f407c15b40bf3b3ad7a";

#import "AppDelegate+USocial.h"

@implementation AppDelegate (USocial)

#pragma mark - 注册友盟分享
- (void)startUmengSocial {
    
    [[UMSocialManager defaultManager] openLog:YES];/* 打开调试日志 */
    [[UMSocialManager defaultManager] setUmSocialAppkey:UMengAppKey];/* 设置友盟appkey */
    [self configUSharePlatforms];/* 配置分享平台 */
}

- (void)configUSharePlatforms {
    
    /* 设置微信的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession
                                          appKey:WeChatAppKey
                                       appSecret:WeChatAppSecret
                                     redirectURL:@"http://mobile.umeng.com/social"];
    
    /* 设置分享到QQ互联的appID */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_QQ
                                          appKey:QQAppKey
                                       appSecret:QQAppSecret
                                     redirectURL:@"http://mobile.umeng.com/social"];
    
    /* 设置新浪的appKey和appSecret */
    [[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_Sina
                                          appKey:SinaAppKey
                                       appSecret:SinaAppSecret
                                     redirectURL:@"https://sns.whalecloud.com/sina2/callback"];
    
//    /* 支付宝的appKey */
//    [[UMSocialManager defaultManager] setPlaform: UMSocialPlatformType_AlipaySession appKey:AliPayAppKey appSecret:nil redirectURL:@"http://mobile.umeng.com/social"];

}


- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(nonnull id)annotation {
    NSLog(@"%@",url);
    //6.3的新的API调用，是为了兼容国外平台(例如:新版facebookSDK,VK等)的调用[如果用6.2的api调用会没有回调],对国内平台没有影响
    BOOL result = [[UMSocialManager defaultManager] handleOpenURL:url sourceApplication:sourceApplication annotation:annotation];
    if (!result) {
        // Ping++支付回调
        result = [Pingpp handleOpenURL:url withCompletion:nil];
    }
    return result;
}

@end
